package com.thqmcp.server.config;

import com.thqmcp.server.websocket.McpWebSocketHandler;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

/**
 * WebSocket配置类
 * 用于支持MCP协议的实时通信
 */
@Configuration
@EnableWebSocket
@RequiredArgsConstructor
public class WebSocketConfig implements WebSocketConfigurer {

    private final McpWebSocketHandler mcpWebSocketHandler;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        // 注册MCP WebSocket处理器
        registry.addHandler(mcpWebSocketHandler, "/mcp/ws")
                .setAllowedOrigins("*"); // 在生产环境中应该限制允许的源
    }
} 